﻿
@{
    ViewBag.Title = "GetSalesLeadByCreateUser";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>GetSalesLeadByCreateUser</h2>
@*<div id="SalesLeadGrid"></div>

<script>
    var leadContactId = 0;
    function showSalesLead(companyId, e) {
        var gridInEditMode = false;
        $('#addcompanyGrid tr.k-state-selected').removeClass('k-state-selected');
        var row = $(e).closest("tr");
        row.addClass("k-state-selected");
        $('#SalesLeadGrid').show();
        //$('#TaskGrid').hide();
        //$('#SubTaskGrid').hide();
        $('#CompanyContactGrid').hide();
        $('#companyofficegrid').hide();
        $('#CompanyHistoryGrid').hide();
        $('#ServiceContractGrid').hide();
        $("#MessageGrid").hide();
        $('#SalesLeadGrid').empty();
        var SalesGridDataSource = new kendo.data.DataSource({

            transport: {
                read: function (options) {

                    $.ajax({
                        type: "POST",
                        url: "../SalesLead/GetSalesLead",
                        contentType: "application/json; charset=utf-8",
                        dataType: 'json',
                        cache: false,
                        data: JSON.stringify({ createdUser: "@User.Identity.Name" }),
                        success: function (data) {
                            debugger;
                            console.log(data);
                            options.success(data);
                        },

                        error: function (request, status, error) {
                            debugger;
                            alert(request.responseText);
                        }
                    });
                }
            }
            });
            
        //var jobdataSource = new kendo.data.DataSource({
        //    transport: {
        //        read: function (options) {
        //            $.ajax({
        //                type: "GET",
        //                url: "../ContactDetail/GetAllJobTitles",
        //                contentType: "application/json; charset=utf-8",
        //                dataType: 'json',
        //                data: JSON.stringify({ key: "Value" }),
        //                success: function (data) {
        //                    options.success(data);
        //                }
        //            });
        //        }
        //    }
        //});
        //var productsdataSource = new kendo.data.DataSource({
        //    transport: {
        //        read: function (options) {
        //            $.ajax({
        //                type: "GET",
        //                url: "../ProductRequestGrid/GetProducts",
        //                contentType: "application/json; charset=utf-8",
        //                dataType: 'json',
        //                data: JSON.stringify({ key: "value" }),
        //                success: function (data) {
        //                    options.success(data);
        //                }
        //            });
        //        }
        //    }
        //});


        //var companycontactsdatasource = new kendo.data.DataSource({
        //    transport: {
        //        read: function (options) {
        //            $.ajax({
        //                type: "POST",

        //                url: "../CommunicationMessageGrid/GetAllCompanyContacts",
        //                contentType: "application/json; charset=utf-8",
        //                dataType: 'json',
        //                data: JSON.stringify({ id: companyId }),
        //                success: function (data) {
        //                    options.success(data);
        //                }
        //            });
        //        }
        //    }
        //});
        //var allcontactsdatasource = new kendo.data.DataSource({
        //    transport: {
        //        read: function (options) {
        //            $.ajax({
        //                type: "GET",
        //                url: "../CommunicationMessageGrid/GetAllContacts",
        //                contentType: "application/json; charset=utf-8",
        //                dataType: 'json',
        //                success: function (data) {
        //                    options.success(data);
        //                }
        //            });
        //        }
        //    }
        //});


        function dateTimeEditor(container, options) {
            $('<input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/>')
            .appendTo(container)
            .kendoDateTimePicker({});
        }
        $("#SalesLeadGrid").kendoGrid({
            dataSource: SalesGridDataSource,
            scrollable: true,
            height: "300px",
            toolbar: [{ name: "create", text: "Create sales" }, "excel"], //, "save", "cancel"],
            excel: {
                allPages: true,
                fileName: "SalesProjectExport.xlsx"
            },
            pageable: true,
            scrollable: true,
            height: 250,
            columns: [
            { field: "loggedOwner", title: "Created User", filterable: false, editable: true },
           { field: "leadcontactname", title: "Lead Name", filterable: false, width: "8em", editor: allcontactsAutoCompleteEditor, editable: true },
            { field: "companycontactname", title: "Company Conatact", editor: companycontactnameDropDownEditor, filterable: true, width: "12em" },
            { field: "product", title: "Product", filterable: true, editor: productsDropDownEditor, width: "8em" },
            { field: "email", title: "Email", filterable: false, width: "8em" },
             { field: "phone", title: "Phone", filterable: true, width: "8em" },

           { field: "numberOfEmployees", title: "Number Of Employee", width: "12em" },
             { field: "annualRevenue", title: "Annual Revenue", hidden: true, format: "{0:c}", hidden: true },
               { field: "deposit", title: "Deposit", format: "{0:c}", hidden: true },
                 { field: "code", title: "Job Title", editor: jobTitleDropDownEditor, width: "8em" },
                 { field: "opportunity", title: "Opportunity", editor: oportunityDropdownEditor, width: "10em" },

          { field: "estimatedCost", title: "Estimated Cost", hidden: true, format: "{0:c}" },
             { field: "actualCost", title: "Actual Cost", format: "{0:c}", hidden: true },
              {
                  field: "dateOpened", title: "Date Opened", width: "10em", filterable: false, format: "{0:MM/dd/yyyy HH:mm tt}",
                  editor: dateTimeEditor,
                  filterable: {
                      ui: "datetimepicker"
                  }
              },
                
                   { field: "daysOpened", title: "How Many Days Opened", filterable: true, width: "12em" },
                    {
                        field: "contractSentDate", title: "Contract Sent", hidden: true, filterable: false, format: "{0:MM/dd/yyyy HH:mm tt}",
                        editor: dateTimeEditor,
                        filterable: {
                            ui: "datetimepicker"
                        }
                    },
                      {
                          field: "contractSignedDate", title: "Contract Signed", hidden: true, filterable: false, format: "{0:MM/dd/yyyy HH:mm tt}",
                          editor: dateTimeEditor,
                          filterable: {
                              ui: "datetimepicker"
                          }
                      },
                         {
                             field: "depositReceivedDate", title: "Deposit Received", hidden: true, filterable: false, format: "{0:MM/dd/yyyy HH:mm tt}",
                             editor: dateTimeEditor,
                             filterable: {
                                 ui: "datetimepicker"
                             }
                         },
                            {
                                field: "startDate", title: "Start Date", filterable: false, editable: true, format: "{0:MM/dd/yyyy HH:mm tt}",
                                editor: dateTimeEditor, width: "8em",
                                filterable: {
                                    ui: "datetimepicker"
                                }
                            },

                 { field: "notes", title: "Notes", width: "10em" },


          {
              title: "&nbsp;",
              width: "10em",

              command: [

                  "edit",
                  {
                      name: "Delete",


                      click: function (e) {

                          var tr = $(e.target).closest("tr"); //get the row for deletion
                          var dataItem = this.dataItem(tr); //get the row data so it can be referred later
                          //see what is coming in dataItem
                          //if (dataItem.QuestionAnswers.length > 0) {
                          //    $("#delValidation").addClass('in')
                          //}
                          //else {

                          deleteTopicConfirmation(e, this);
                          //   }
                          return false;
                      }
                  }
              ]
          }
            ],
            filterable: {
                extra: false,
                operators: {
                    string: {
                        eq: "Is equal to",
                        neq: "Is not equal to",
                        contains: "Contains"
                    }
                }
            },

            editable: "popup",

            sortable: {
                mode: "single",
                allowUnsort: false
            },
            selectable: true,
            edit: function () {
                //   e.container.find(".k-edit-label:nth-child(3)").hide();
                gridInEditMode = true;
            },
            excelExport: function (e) {
                for (var i = 0; i < e.workbook.sheets[0].columns.length; i++) {
                    e.workbook.sheets[0].columns[i].autoWidth = true;
                }
            },
            cancel: function () {
                gridInEditMode = false;
            },

        });
        SalesGridDataSource.bind("requestEnd", showSuccessMessage);
        $(".close").click(function () {
            $(this).parent().removeClass('in');
        });
        function showSuccessMessage(e) {
            if (e.type === "update" || e.type === "create") {
                gridInEditMode = false;
                $("#saveConfirm").addClass('in');
                e.sender.read();
            }
        }

  
        function deleteTopicConfirmation(e, widget) {
            var grid = $('#SalesLeadGrid').data("kendoGrid");
            deleteConfirmation(e, widget, grid);
        }

        function deleteConfirmation(e, widget, grid) {

            var currentRow = $(e.target).closest("tr"); //get the row for deletion

            var currentRowData = widget.dataItem(currentRow); //get the row data so it can be  referred later

            var kendoWindow = $("<div />").kendoWindow({

                title: "Confirmation",
                resizable: true,
                modal: true,
                width: "400px"
            });

            kendoWindow.data("kendoWindow")

                .content($("#delete-confirmation").html())

                .center().open();

            kendoWindow

                .find(".delete-confirm,.delete-cancel")
                .click(function () {
                    if ($(this).hasClass("delete-confirm")) {

                        grid.dataSource.remove(currentRowData);

                        grid.dataSource.sync();

                    }

                    $(this).closest("[data-role=window]").kendoWindow("close");

                });

        }
    }

</script>*@

